package com.gongpingjialoan.activity.sell;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.gongpingjialoan.R;
import com.gongpingjialoan.activity.main.BaseActivity;
import com.gongpingjialoan.activity.main.BaseScrollFragment;
import com.gongpingjialoan.activity.main.SelectAddressActivity;
import com.gongpingjialoan.adapter.PhotoGridAdapter;
import com.gongpingjialoan.api.API;
import com.gongpingjialoan.bean.ModifyBean;
import com.gongpingjialoan.bean.PhotoModel;
import com.gongpingjialoan.bean.PriCarPhotoItem;
import com.gongpingjialoan.bean.SellPrivateDetail;
import com.gongpingjialoan.constant.Const;
import com.gongpingjialoan.network.NetDataJson;
import com.gongpingjialoan.network.UploadCallBack;
import com.gongpingjialoan.utility.PhotoUtil;
import com.gongpingjialoan.utility.UploadUtils;
import com.gongpingjialoan.utility.Utils;
import com.gongpingjialoan.widget.AddMaintainView;
import com.gongpingjialoan.widget.ModifySellCarMessageDialog;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/10/11.
 */
public class OffSellPrivateCarDetailFragment extends BaseScrollFragment implements View.OnClickListener {

    private BaseActivity mActivity;

    private NetDataJson modifyNetDataJson;

    private String mPhotoPath;

    private int index;

    private String type = "", value = "";

    private PriCarPhotoItem photoItem;

    private File dir;

    private View popupView, layout_get_pic, layout_take_pic, topview;

    private TextView carNameTextView, timeTextView, mileTextView, statusTextView,
            priceTextView, nameTextView, phoneTextView, addressTextView, desSureTextView, reasonTextView;

    private ImageView modAddressImageView, modPhoneImageView, modNameImageView, modPriceImageView, imgView_close_layout;

    private List<PriCarPhotoItem> mPriCarPhotoItems, indePriCarPhotoItems;

    private GridView carPhotoMyGridView, indMyGridView;

    private AddMaintainView baoyangView, chuxiangView, otherAddMaintainView;

    private PhotoGridAdapter mCarPhotoGridAdapter, indPhotoGridAdapter;

    private PopupWindow mPopupWindow;

    private EditText desEditText;

    private ModifySellCarMessageDialog mModifySellCarMessageDialog;

    private static final int REQUEST_IMG_TAKE = 8;

    private static final int REQUEST_CROP_CAMERA_BAOYANG = 22;

    private static final int REQUEST_CROP_CAMERA_CHUXIAN = 23;

    private static final int REQUEST_CROP_CAMERA_QITA = 25;

    private static final int REQUEST_CAMERA_BAOYANG = 100;

    private static final int REQUEST_CAMERA_CHUXIAN = 101;

    private static final int REQUEST_CAMERA_QITA = 102;

    private static final int REQUEST_CROP = 7;

    private static final int GETADDRESS = 10;


    private SellPrivateDetail.DataEntity dataEntity;

    private View view;

    public OffSellPrivateCarDetailFragment(SellPrivateDetail.DataEntity dataEntity) {
        this.dataEntity = dataEntity;
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.off_sellprivate_layout, container, false);
        initView();
        initData();
        return view;
    }


    private void initView() {
        mActivity = (BaseActivity) getActivity();
        dir = new File(mActivity.getExternalCacheDir(), "gpj");
        if (!dir.exists()) dir.mkdirs();

        reasonTextView = (TextView) view.findViewById(R.id.reason);
        desEditText = (EditText) view.findViewById(R.id.des_edit);
        desSureTextView = (TextView) view.findViewById(R.id.des_sure);
        carNameTextView = (TextView) view.findViewById(R.id.carName);
        timeTextView = (TextView) view.findViewById(R.id.time);
        mileTextView = (TextView) view.findViewById(R.id.mile);
        statusTextView = (TextView) view.findViewById(R.id.status);
        priceTextView = (TextView) view.findViewById(R.id.price);
        nameTextView = (TextView) view.findViewById(R.id.name);
        phoneTextView = (TextView) view.findViewById(R.id.phone);
        addressTextView = (TextView) view.findViewById(R.id.address);
        carPhotoMyGridView = (GridView) view.findViewById(R.id.car_photos);
        indMyGridView = (GridView) view.findViewById(R.id.ind_photos);

        modAddressImageView = (ImageView) view.findViewById(R.id.mod_address);
        modPhoneImageView = (ImageView) view.findViewById(R.id.mod_phone);
        modNameImageView = (ImageView) view.findViewById(R.id.mod_name);
        modPriceImageView = (ImageView) view.findViewById(R.id.mod_price);

        popupView = LayoutInflater.from(mActivity).inflate(R.layout.include_popup, null);
        mPopupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        mPopupWindow.setAnimationStyle(R.style.PopupMenu);
        mPopupWindow.setFocusable(true);
        mPopupWindow.setOutsideTouchable(true);
        // 需要设置一下此参数，点击外边可消失
        mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
        topview = popupView.findViewById(R.id.topview);
        layout_get_pic = popupView.findViewById(R.id.layout_get_pic);
        layout_take_pic = popupView.findViewById(R.id.layout_take_pic);
        imgView_close_layout = (ImageView) popupView.findViewById(R.id.imgView_close_layout);
        int size = 0;
        //车源照片
        mPriCarPhotoItems = new ArrayList<>();
        size = Const.CarTypes.length;
        for (int i = 0; i < size; i++) {
            mPriCarPhotoItems.add(new PriCarPhotoItem("", Const.CarTypes[i], Const.CarNames[i]));
        }

        carPhotoMyGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (TextUtils.isEmpty(mPriCarPhotoItems.get(position).getImgUrl())) {
                    topview.setVisibility(View.VISIBLE);
                    index = position;
                    mPopupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
                }
            }
        });

        //卖车必备
        indePriCarPhotoItems = new ArrayList<>();
        size = Const.IndTypes.length;
        for (int i = 0; i < size; i++) {
            indePriCarPhotoItems.add(new PriCarPhotoItem("", Const.IndTypes[i], Const.IndNames[i]));
        }

        indMyGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (TextUtils.isEmpty(indePriCarPhotoItems.get(position).getImgUrl())) {
                    topview.setVisibility(View.GONE);
                    index = position;
                    mPopupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
                }
            }
        });

        baoyangView = (AddMaintainView) view.findViewById(R.id.maintain);
        chuxiangView = (AddMaintainView) view.findViewById(R.id.chuxian);
        otherAddMaintainView = (AddMaintainView) view.findViewById(R.id.other);
        baoyangView.setTitle("最近保养记录");
        chuxiangView.setTitle("最近出险记录");
        otherAddMaintainView.setTitle("其它图片");
        baoyangView.setMaxNum(3);
        chuxiangView.setMaxNum(3);
        baoyangView.setId(REQUEST_CAMERA_BAOYANG);
        chuxiangView.setId(REQUEST_CAMERA_CHUXIAN);
        otherAddMaintainView.setId(REQUEST_CAMERA_QITA);

        layout_get_pic.setOnClickListener(this);
        layout_take_pic.setOnClickListener(this);
        desSureTextView.setOnClickListener(this);
        imgView_close_layout.setOnClickListener(this);
        modAddressImageView.setOnClickListener(this);
        modPriceImageView.setOnClickListener(this);
        modNameImageView.setOnClickListener(this);
        modPhoneImageView.setOnClickListener(this);


    }

    private void initData() {

        carNameTextView.setText(dataEntity.getTitle());
        if (dataEntity.getCreate_time().length() > 10) {
            timeTextView.setText(dataEntity.getCreate_time().substring(0, 10));
        }

        if ("F".equals(dataEntity.getStatus()) && !TextUtils.isEmpty(dataEntity.getFailed_reason())) {
            reasonTextView.setText("审核不通过: " + dataEntity.getFailed_reason());
            reasonTextView.setVisibility(View.VISIBLE);
        } else {
            reasonTextView.setVisibility(View.GONE);
        }
        String status = "信息状态: " + dataEntity.getStatus_zh();
        statusTextView.setText(Utils.changeColor(mActivity, status, 0, 6, R.color.discount_price_other_color));
        mileTextView.setText(dataEntity.getYear() + "年上牌/" + dataEntity.getMile() + "万公里");
        priceTextView.setText(dataEntity.getPrice() + "万");
        nameTextView.setText(dataEntity.getContact());
        phoneTextView.setText(dataEntity.getPhone());
        addressTextView.setText(dataEntity.getRegion());
        desEditText.setText(dataEntity.getDescription());
        List<SellPrivateDetail.DataEntity.ImagesEntity> imagesEntities = dataEntity.getImages();
        if (imagesEntities != null) {
            int size = imagesEntities.size();
            int length = mPriCarPhotoItems.size();
            for (int i = 0; i < size; i++) {
                String type = imagesEntities.get(i).getName();
                for (int j = 0; j < length; j++) {
                    if (type.equals(mPriCarPhotoItems.get(j).getName())) {
                        mPriCarPhotoItems.get(j).setImgUrl(imagesEntities.get(i).getUrl());
                    }
                }
            }
            mCarPhotoGridAdapter = new PhotoGridAdapter(mPriCarPhotoItems, mActivity, true);
            carPhotoMyGridView.setAdapter(mCarPhotoGridAdapter);
        }

        List<SellPrivateDetail.DataEntity.ImagesEntity> indImagesEntityList = dataEntity.getIdentify_images();
        if (indImagesEntityList != null) {
            int size = indImagesEntityList.size();
            int length = indePriCarPhotoItems.size();
            for (int i = 0; i < size; i++) {
                String type = indImagesEntityList.get(i).getName();
                for (int j = 0; j < length; j++) {
                    if (type.equals(indePriCarPhotoItems.get(j).getName())) {
                        indePriCarPhotoItems.get(j).setImgUrl(indImagesEntityList.get(i).getUrl());
                    }
                }
            }
            indPhotoGridAdapter = new PhotoGridAdapter(indePriCarPhotoItems, mActivity, true);
            indMyGridView.setAdapter(indPhotoGridAdapter);
        }


        List<SellPrivateDetail.DataEntity.ImagesEntity> maintenanceImages = dataEntity.getMaintenance_images();
        if (maintenanceImages != null && maintenanceImages.size() > 0) {
            List<PhotoModel> images = new ArrayList<>();
            int size = maintenanceImages.size();
            for (int i = 0; i < size; i++) {
                PhotoModel photoModel = new PhotoModel();
                photoModel.setUploadedUrl(maintenanceImages.get(i).getUrl());
                photoModel.setIsLoading(true);
                photoModel.setId(0);
                images.add(photoModel);
            }
            baoyangView.setData(images);
        }

        List<SellPrivateDetail.DataEntity.ImagesEntity> insureImagesEntityList = dataEntity.getInsurance_images();
        if (insureImagesEntityList != null && insureImagesEntityList.size() > 0) {
            List<PhotoModel> images = new ArrayList<>();
            int size = insureImagesEntityList.size();
            for (int i = 0; i < size; i++) {
                PhotoModel photoModel = new PhotoModel();
                photoModel.setUploadedUrl(insureImagesEntityList.get(i).getUrl());
                photoModel.setIsLoading(true);
                photoModel.setId(0);
                images.add(photoModel);
            }
            chuxiangView.setData(images);
        }


        List<SellPrivateDetail.DataEntity.ImagesEntity> otherImagesEntities = dataEntity.getOther_images();
        if (otherImagesEntities != null && otherImagesEntities.size() > 0) {
            List<PhotoModel> images = new ArrayList<>();
            int size = otherImagesEntities.size();
            for (int i = 0; i < size; i++) {
                PhotoModel photoModel = new PhotoModel();
                photoModel.setUploadedUrl(otherImagesEntities.get(i).getUrl());
                photoModel.setIsLoading(true);
                photoModel.setId(0);
                images.add(photoModel);
            }
            otherAddMaintainView.setData(images);
        }

    }


    @Override
    public void onClick(View v) {
        if (v == desSureTextView) {
            String str = desEditText.getText().toString();
            if (TextUtils.isEmpty(str)) {
                Toast.makeText(mActivity, "请输入车辆描述信息", Toast.LENGTH_SHORT).show();
                return;
            }
            modifyData(new ModifyBean("description", str));
            this.type = "description";

        } else if (v == layout_get_pic) {
            mPopupWindow.dismiss();
            Intent intent = new Intent(mActivity,
                    PhotoSelectorActivity.class);
            intent.putExtra(PhotoSelectorActivity.KEY_MAX,
                    1);
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            startActivityForResult(intent, Const.PICK_PHOTO);
        } else if (v == layout_take_pic) {
            mPopupWindow.dismiss();
            mPhotoPath = new File(dir, System.currentTimeMillis() + ".jpg")
                    .getAbsolutePath();
            PhotoUtil.getPhotoFromCamera(mActivity, REQUEST_IMG_TAKE, mPhotoPath);
        } else if (v == modAddressImageView) {
            startActivityForResult(new Intent(mActivity, SelectAddressActivity.class), GETADDRESS);
        } else if (v == modPriceImageView) {
            mModifySellCarMessageDialog = new ModifySellCarMessageDialog(mActivity, "price");
            mModifySellCarMessageDialog.show();
        } else if (v == modNameImageView) {
            mModifySellCarMessageDialog = new ModifySellCarMessageDialog(mActivity, "contact");
            mModifySellCarMessageDialog.show();
        } else if (v == modPhoneImageView) {
            mModifySellCarMessageDialog = new ModifySellCarMessageDialog(mActivity, "phone");
            mModifySellCarMessageDialog.show();
        } else if (v == imgView_close_layout) {
            mPopupWindow.dismiss();
        }
    }


    public JSONArray getGridViewImages(PhotoGridAdapter adapter, String[] types) throws JSONException {
        JSONArray jsa = new JSONArray();
        int size = adapter.getCount();
        for (int i = 0; i < size; i++) {
            PriCarPhotoItem item = (PriCarPhotoItem) adapter.getItem(i);
            if (!TextUtils.isEmpty(item.getImgUrl())) {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("name", types[i]);
                jsonObject.put("url", item.getImgUrl());
                jsa.put(jsonObject);
            }
        }
        return jsa;
    }


    public void modifyMessage(String type, String value) {
        this.type = type;
        this.value = value;
        modifyData(new ModifyBean(type, value));
    }


    public void modifyData(ModifyBean modifyBean) {
        try {
            if (modifyNetDataJson == null) {
                modifyNetDataJson = new NetDataJson(new NetDataJson.OnNetDataJsonListener() {
                    @Override
                    public void onDataJsonError(String errorMessage) {
                        mActivity.hidenProgressDialog();
                        if ("images".equals(OffSellPrivateCarDetailFragment.this.type) || "identify_images".equals(OffSellPrivateCarDetailFragment.this.type)) {
                            if (photoItem != null) {
                                photoItem.setImgUrl("");
                            }
                        }
                        Toast.makeText(mActivity, errorMessage, Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onDataJsonUpdate(JSONObject json) {
                        mActivity.hidenProgressDialog();
                        if ("images".equals(OffSellPrivateCarDetailFragment.this.type)) {
                            mCarPhotoGridAdapter.notifyDataSetChanged();
                        } else if ("identify_images".equals(OffSellPrivateCarDetailFragment.this.type)) {
                            indPhotoGridAdapter.notifyDataSetChanged();
                        } else if ("region".equals(OffSellPrivateCarDetailFragment.this.type)) {
                            addressTextView.setText(addressTextView.getTag().toString());
                        } else if ("phone".equals(OffSellPrivateCarDetailFragment.this.type)) {
                            phoneTextView.setText(value);
                        } else if ("contact".equals(OffSellPrivateCarDetailFragment.this.type)) {
                            nameTextView.setText(value);
                        } else if ("price".equals(OffSellPrivateCarDetailFragment.this.type)) {
                            priceTextView.setText(value + "万");
                        }
                        SellPrivateCarDetailActivity sellPrivateCarDetailActivity = (SellPrivateCarDetailActivity) mActivity;
                        if (sellPrivateCarDetailActivity != null)
                            sellPrivateCarDetailActivity.isModify = true;
                        Toast.makeText(mActivity, "修改成功!", Toast.LENGTH_SHORT).show();
                    }
                });
                modifyNetDataJson.setUrl(API.modify_private_car);
                modifyNetDataJson.addParam("brand", dataEntity.getBrand());
                modifyNetDataJson.addParam("model", dataEntity.getModel());
                modifyNetDataJson.addParam("model_detail", dataEntity.getModel_detail());
                modifyNetDataJson.addParam("year", dataEntity.getYear());
                modifyNetDataJson.addParam("month", dataEntity.getMonth());
                modifyNetDataJson.addParam("mile", dataEntity.getMile());
                modifyNetDataJson.addParam("city", dataEntity.getCity());
                modifyNetDataJson.addParam("price", dataEntity.getPrice());
                modifyNetDataJson.addParam("region", dataEntity.getRegion());
                modifyNetDataJson.addParam("contact", dataEntity.getContact());
                modifyNetDataJson.addParam("phone", dataEntity.getPhone());
                modifyNetDataJson.addParam("id", dataEntity.getId());
                modifyNetDataJson.addParam("description", dataEntity.getDescription());
                modifyNetDataJson.addParam("images", getGridViewImages(mCarPhotoGridAdapter, Const.CarTypes).toString());
                modifyNetDataJson.addParam("identify_images", getGridViewImages(indPhotoGridAdapter, Const.IndTypes).toString());
                modifyNetDataJson.addParam("maintenance_images", baoyangView.getUrls().toString());
                modifyNetDataJson.addParam("insurance_images", chuxiangView.getUrls().toString());
                modifyNetDataJson.addParam("other_images", otherAddMaintainView.getUrls().toString());

            }
            modifyNetDataJson.addParam(modifyBean.type, modifyBean.value);
            modifyNetDataJson.request("post");
            mActivity.showProgressDialog("加载中...");
        } catch (JSONException e) {

        }
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            // Bundle bundle = data.getExtras();
            switch (requestCode) {
                case Const.PICK_MAINTAIN:
                    if (data.getIntExtra("id", 0) == REQUEST_CAMERA_BAOYANG) {
                        baoyangView.photoCallBack(data);
                    }
                    if (data.getIntExtra("id", 0) == REQUEST_CAMERA_CHUXIAN) {
                        chuxiangView.photoCallBack(data);
                    }
                    if (data.getIntExtra("id", 0) == REQUEST_CAMERA_QITA) {
                        otherAddMaintainView.photoCallBack(data);
                    }
                    break;
                case REQUEST_CROP_CAMERA_BAOYANG:
                    baoyangView.cameraCallback();
                    break;

                case REQUEST_CROP_CAMERA_CHUXIAN:
                    chuxiangView.cameraCallback();
                    break;

                case REQUEST_CROP_CAMERA_QITA:
                    otherAddMaintainView.cameraCallback();
                    break;

                case REQUEST_CAMERA_BAOYANG:
                    PhotoUtil.onPhotoFromCamera(mActivity, REQUEST_CROP_CAMERA_BAOYANG, baoyangView.camearPath, 3,
                            2, 2000);
                    break;

                case REQUEST_CAMERA_CHUXIAN:
                    PhotoUtil.onPhotoFromCamera(mActivity, REQUEST_CROP_CAMERA_CHUXIAN, chuxiangView.camearPath, 3,
                            2, 2000);
                    break;

                case REQUEST_CAMERA_QITA:
                    PhotoUtil.onPhotoFromCamera(mActivity, REQUEST_CROP_CAMERA_QITA, otherAddMaintainView.camearPath, 3,
                            2, 2000);
                    break;
                case Const.PICK_PHOTO:
                    mActivity.showProgressDialog("图片上传中...");
                    if (data != null && data.getExtras() != null) {
                        List<PhotoModel> photos = (List<PhotoModel>) data.getExtras().getSerializable("photos");
                        if (photos == null || photos.isEmpty()) {
                            Toast.makeText(mActivity, "没有选择图片!", Toast.LENGTH_SHORT).show();
                            mActivity.hidenProgressDialog();
                        } else {
                            String newPhotoPath = new File(dir, System.currentTimeMillis() + ".jpg")
                                    .getAbsolutePath();
                            Bitmap btp = PhotoUtil.getLocalImage(new File(photos.get(0).getOriginalPath()));
                            PhotoUtil.saveLocalImageSquare(btp, new File(newPhotoPath));
                            uploadImg(newPhotoPath);
                        }
                    }
                    break;
                case REQUEST_IMG_TAKE:
                    PhotoUtil.onPhotoFromCamera(mActivity, REQUEST_CROP, mPhotoPath, 3,
                            2, 2000);
                    break;
                case REQUEST_CROP:
                    mActivity.showProgressDialog("图片上传中...");
                    uploadImg(mPhotoPath);
                    break;
                case GETADDRESS:
                    String address = data.getExtras().getString("address_title") + data.getExtras().getString("address_detail");
                    addressTextView.setTag(address);
                    this.type = "region";
                    modifyData(new ModifyBean("region", address));
                    break;
            }
        }
    }


    public void setPhotoPath(String type, PhotoGridAdapter adapter, String uri, String[] types) {
        photoItem = (PriCarPhotoItem) adapter.getItem(index);
        photoItem.setImgUrl(uri);
        String value = null;
        try {
            value = getGridViewImages(adapter, types).toString();
        } catch (JSONException e) {
        }
        modifyData(new ModifyBean(type, value));
        this.type = type;
    }


    public void deleteImg(ViewGroup parent, PriCarPhotoItem item, PhotoGridAdapter adapter) {
        String[] types;
        if (parent == carPhotoMyGridView) {
            this.type = "images";
            types = Const.CarTypes;
        } else {
            this.type = "identify_images";
            types = Const.IndTypes;
        }
        String value = null;
        try {
            value = getGridViewImages(adapter, types).toString();
        } catch (JSONException e) {
        }
        modifyData(new ModifyBean(type, value));
    }

    public void addImgFromMaintan(int id) {
        try {
            if (id == REQUEST_CAMERA_BAOYANG) {
                this.type = "maintenance_images";
                modifyData(new ModifyBean(this.type, baoyangView.getUrls().toString()));
            } else if (id == REQUEST_CAMERA_CHUXIAN) {
                this.type = "insurance_images";
                modifyData(new ModifyBean(this.type, chuxiangView.getUrls().toString()));
            } else if (id == REQUEST_CAMERA_QITA) {
                this.type = "other_images";
                modifyData(new ModifyBean(this.type, otherAddMaintainView.getUrls().toString()));
            }
        } catch (JSONException e) {
        }
    }


    private void uploadImg(String path) {
        UploadUtils.uploadImage(path, new UploadCallBack() {
            @Override
            public void success(final String uri) {
                mActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mActivity.hidenProgressDialog();
                        if (topview.getVisibility() == View.VISIBLE) {
                            setPhotoPath("images", mCarPhotoGridAdapter, uri, Const.CarTypes);
                        } else {
                            setPhotoPath("identify_images", indPhotoGridAdapter, uri, Const.IndTypes);
                        }
                        Toast.makeText(mActivity, "上传成功", Toast.LENGTH_SHORT).show();
                    }
                });
            }

            @Override
            public void failure() {
                mActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mActivity.hidenProgressDialog();
                        Toast.makeText(mActivity, "上传失败", Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }, API.uploadPic, "");
    }


    @Override
    public void onDestroy() {
        super.onDestroy();

        if (modifyNetDataJson != null) {
            modifyNetDataJson.cancelTask();
            modifyNetDataJson = null;
        }

    }


}
